package com.ruoyi.web.controller.ring;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.dict.RingBannerType;
import com.ruoyi.common.enums.dict.SysNormalDisable;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.HealthQuestion;
import com.ruoyi.ring.domain.RingBanner;
import com.ruoyi.ring.service.IRingBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * bannerController
 * 
 * @author liuwp
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/ring/ring_banner")
public class RingBannerController extends BaseController
{
    @Autowired
    private IRingBannerService ringBannerService;

    /**
     * 查询banner列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(RingBanner ringBanner)
    {
        startPage();
        List<RingBanner> list = ringBannerService.selectRingBannerList(ringBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_banner:export')")
    @Log(title = "banner", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RingBanner ringBanner)
    {
        List<RingBanner> list = ringBannerService.selectRingBannerList(ringBanner);
        ExcelUtil<RingBanner> util = new ExcelUtil<RingBanner>(RingBanner.class);
        util.exportExcel(response, list, "banner数据");
    }

    /**
     * 获取banner详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ringBannerService.selectRingBannerById(id));
    }

    /**
     * 新增banner
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_banner:add')")
    @Log(title = "banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RingBanner ringBanner)
    {
        return toAjax(ringBannerService.insertRingBanner(ringBanner));
    }

    /**
     * 修改banner
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_banner:edit')")
    @Log(title = "banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RingBanner ringBanner)
    {
        return toAjax(ringBannerService.updateRingBanner(ringBanner));
    }

    /**
     * 删除banner
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_banner:remove')")
    @Log(title = "banner", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ringBannerService.deleteRingBannerByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('ring:ring_banner:list')")
    @GetMapping("/query")
    public AjaxResult query(RingBanner ringBanner)
    {
        ringBanner.setStatus(SysNormalDisable.NORMAL.getValue());
        ringBanner.setBannerType(RingBannerType.TYPE1.getValue());
        PageHelper.orderBy("order_by desc");
        List<RingBanner> list = ringBannerService.selectRingBannerList(ringBanner);
        return AjaxResult.success(list);
    }
}
